package com.ruihang.generalibrary.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.jiongbull.jlog.JLog;

/**
 * Created by Administrator on 2017/3/16.
 */

public class NetModeUtil {
    //返回值 -1：没有网络  0：非联通网络  1： 联通  2：WIFI网络
    public static int GetNetype(Context context) {
        int netType = -1;
        ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo == null) {
            return netType;
        }
        int nType = networkInfo.getType();
        JLog.e("net type=" + nType);
        if (nType == ConnectivityManager.TYPE_MOBILE) {
//            if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {
//                netType = 3;
//            } else {
//                netType = 2;
//            }
            netType=0;
        } else if (nType == ConnectivityManager.TYPE_WIFI) {
            netType = 1;
        }
        return netType;
    }

    public static int GetTMMode(Context context){
        int mode=0;
        TelephonyManager tm= (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String operator=tm.getSimOperator();
        if (!TextUtils.isEmpty(operator) && operator.equals("46001")){
            mode=1;
        }
        return mode;
    }
}
